from amplitude.model import Model
import roles

class Right(Model):
    relation = 'rights'
    pk_fields = ['name']

    def roles(self, update=False):
        """many-to-many relationship through rights_roles"""
        if update==True or self._roles is None:
            self._roles = roles.Role(self.db).select(where="name in (select rolename from rights_roles where rightname='%(name)s')" % self)
        return self._roles
